package com.boarsoft.message.test.activemq.amqp;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.boarsoft.common.util.JsonUtil;
import com.boarsoft.message.bean.Message;

@Deprecated
public class ListenerTest1 {
	private static final Logger log = LoggerFactory.getLogger(ListenerTest1.class);

	public static void main(String[] args) throws JMSException {
		ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://20.3.6.172:61616");
		// JmsConnectionFactory factory = new
		// JmsConnectionFactory("amqp://192.168.1.12:5672");
		Connection connection = factory.createConnection("admin", "admin");
		connection.start();
		final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
		Destination destination = session.createQueue("sms_debit");
		final MessageConsumer consumer = session.createConsumer(destination);
		System.out.println("Waiting for messages...");
		while (true) {
			String o = ((TextMessage) consumer.receive()).getText();
			Message m = JsonUtil.parseObject(o, Message.class);
			// Object o = ((ObjectMessage) msg).getObject();
			log.info("Received text message {}", m);
		}
	}
}